package com.java.tutorials.jdk7.locale;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
/**
 * Created by xuzhike on 2016/1/27.
 * http://www.java2s.com/Code/Java/JDK-7/CreateLocalefromLanguage.htm
 */
public class CreateLocalefromLanguage {
    public static void main(String[] args) {
        long SAMPLE_NUMBER = 123456789L;
        Date NOW = new Date();
        System.out.printf("Creating from BCP 47 language tags...\n\n");
        String[] bcp47LangTags= {"fr-FR", "ja-JP", "en-US"};
        Locale l = null;
        for (String langTag: bcp47LangTags) {
            l = Locale.forLanguageTag(langTag);
            displayLocalizedData(l, SAMPLE_NUMBER, NOW);
        }
    }

    static void displayLocalizedData(Locale l, long number, Date date) {
        NumberFormat nf = NumberFormat.getInstance(l);
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
                DateFormat.LONG, l);
        System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n",
                l.getDisplayName(), nf.format(number), df.format(date));
    }
}
